﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JAMR.Rendering.GeometricObjects;
using Substrate;
using Substrate.Core;

namespace JAMR.Rendering.Blocks
{
    public class Grass : RenderableBlock
    {
        private string TexSideGrass;
        private string TexSideSnow;
        private string TexSideTop;
        private string TexSideBottom;

        private static FoliageCache foliage = FoliageCache.Instance;

        public Grass(string texSideGrass, string texSideSnow, string texTop, string texBot)
        {
            TexSideGrass = texSideGrass;
            TexSideSnow = texSideSnow;
            TexSideTop = texTop;
            TexSideBottom = texBot;
        }

        public override void Draw(OpenTK.Vector3 location, int data, IBlockManager blocks)
        {
            // If data & 0x10, then snow side
            bool snow = (data & 0x10) == 0x10;

            // TODO: Do biome calculations
            string thisGrassTop = TexSideTop;
            string thisGrassSide = TexSideGrass;

            if (foliage.HasImage)
            {
                // Default, first pixel
                thisGrassTop = FoliageCache.Instance.GetTexture(TexSideTop, 0);
                thisGrassSide = FoliageCache.Instance.GetTexture(thisGrassSide, 0);
            }

            // Make cube
            BlockTexture tex = new BlockTexture();

            tex.TextureBottom = TexSideBottom;
            tex.SetAllSides(snow ? TexSideSnow : thisGrassSide);
            tex.TextureTop = thisGrassTop;

            Cube s = new Cube(location);
            s.Draw(tex);
        }
    }
}
